<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h3>书架</h3>
        <ul>
            <li v-for="book in booklist" :key="book.id">
                <span>{{book.name}}</span>
                <span>{{book.author}}</span>
                <button @click="del(book.id)">删除</button>
            </li>
        </ul>
    </div>

    <!-- 引入开发版本的包 - 包含完整的注释和警告-->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <script>
        // 创建Vue实例
        const app = new Vue({
            el: '#app',
            data:
            {
                booklist: [
                    { id: 1, name: '《红楼梦》', author: '曹雪芹' },
                    { id: 2, name: '《西游记》', author: '吴承恩' },
                    { id: 3, name: '《水浒传》', author: '施耐庵' },
                    { id: 4, name: '《三国演义》', author: '罗贯中' }
                ]
            },
            methods: {
                del(id) {
                    //filter:根据条件，保留满足条件的对应项，得到一个新数组。
                    this.booklist = this.booklist.filter(item => item.id !== id)
                }
            }
        })
    </script>
</body>